package com._520it.crm.web.controller;

import com._520it.crm.domain.Client;
import com._520it.crm.domain.ClientCarInfo;
import com._520it.crm.domain.InsuranceInfoChange;
import com._520it.crm.page.PageResult;
import com._520it.crm.query.InsuranceInfoChangeQueryObject;
import com._520it.crm.query.OrderBillQueryObject;
import com._520it.crm.service.IClientCarInfoService;
import com._520it.crm.service.IClientService;
import com._520it.crm.service.IInsuranceInfoChangeService;
import com._520it.crm.service.IOrderBillService;
import com._520it.crm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by 呆 on 2017/10/3.
 */
@Controller
@RequestMapping("/correctingRequisition")
public class CorrectingRequisitionController {
    @Autowired
    private IInsuranceInfoChangeService correctingRequisitionService;
    @Autowired
    private IClientService clientService;
    @Autowired
    private IClientCarInfoService clientCarInfoService;
    @Autowired
    private IOrderBillService orderBillService;
    @RequestMapping("")
    public String index(String insurancePolicyNumber,Model model){
        model.addAttribute("insurancePolicyNumber",insurancePolicyNumber);
        return "correctingRequisition";
    }


    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(OrderBillQueryObject qo)
    {

        try {
            return orderBillService.queryByApplystate(qo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @RequestMapping("/approvalByInsurancePolicyNumber")
    @ResponseBody
    public InsuranceInfoChange approvalById(String insurancePolicyNumber)
    {
        try {
            InsuranceInfoChange correctingRequisition = correctingRequisitionService.approvalByInsurancePolicyNumber(insurancePolicyNumber);
            return correctingRequisition;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    @RequestMapping("/client")
    @ResponseBody
    public Client clientCar(Model model)
    {
        model.addAttribute("id",1L);
        Client client = clientService.selectByPrimaryKey(1L);
        return client;
    }
    @RequestMapping("/queryClientCar")
    @ResponseBody
    public ClientCarInfo list(Model model)
    {
        model.addAttribute("id",1L);
        ClientCarInfo car = clientCarInfoService.selectByPrimaryKey(1L);
        return car;
    }
    @RequestMapping("/updateInsuranceWithOrderBill")
    @ResponseBody
    public AjaxResult save(InsuranceInfoChange correctingRequisition)
    {
        try {
            correctingRequisitionService.insertMutiplate(correctingRequisition);
            return new AjaxResult("保存成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"保存失败");
        }
    }
}
